home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / uemacs-3.000 / uemacs-3 / uemacs-3.8 / ansi.c,v next >
Encoding:
Text File  |  1995-09-22  |  4.5 KB  |  273 lines

  1. head    1.1;
  2. access;
  3. symbols;
  4. locks
  5.     moss:1.1; strict;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.1
  10. date    95.09.22.22.56.11;    author moss;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19. 1.1
  20. log
  21. @Initial revision
  22. @
  23. text
  24. @/*
  25.  * The routines in this file provide support for ANSI style terminals
  26.  * over a serial line. The serial I/O services are provided by routines in
  27.  * "termio.c". It compiles into nothing if not an ANSI device.
  28.  */
  29.  
  30. #define    termdef    1            /* don't define "term" external */
  31.  
  32. #include        <stdio.h>
  33. #include    "estruct.h"
  34. #include        "edef.h"
  35.  
  36. #if     ANSI
  37.  
  38. #if    AMIGA
  39. #define NROW    23                      /* Screen size.                 */
  40. #define NCOL    77                      /* Edit if you want to.         */
  41. #else
  42. #define NROW    25                      /* Screen size.                 */
  43. #define NCOL    80                      /* Edit if you want to.         */
  44. #endif
  45. #define    NPAUSE    100            /* # times thru update to pause */
  46. #define    MARGIN    8            /* size of minimim margin and    */
  47. #define    SCRSIZ    64            /* scroll size for extended lines */
  48. #define BEL     0x07                    /* BEL character.               */
  49. #define ESC     0x1B                    /* ESC character.               */
  50.  
  51. extern  int     ttopen();               /* Forward references.          */
  52. extern  int     ttgetc();
  53. extern  int     ttputc();
  54. extern  int     ttflush();
  55. extern  int     ttclose();
  56. extern  int     ansimove();
  57. extern  int     ansieeol();
  58. extern  int     ansieeop();
  59. extern  int     ansibeep();
  60. extern  int     ansiopen();
  61. extern    int    ansirev();
  62. extern    int    ansiclose();
  63. extern    int    ansikopen();
  64. extern    int    ansikclose();
  65. extern    int    ansicres();
  66.  
  67. #if    COLOR
  68. extern    int    ansifcol();
  69. extern    int    ansibcol();
  70.  
  71. int    cfcolor = -1;        /* current forground color */
  72. int    cbcolor = -1;        /* current background color */
  73. #endif
  74.  
  75. /*
  76.  * Standard terminal interface dispatch table. Most of the fields point into
  77.  * "termio" code.
  78.  */
  79. TERM    term    = {
  80.     NROW-1,
  81.         NROW-1,
  82.         NCOL,
  83.         NCOL,
  84.     MARGIN,
  85.     SCRSIZ,
  86.     NPAUSE,
  87.         ansiopen,
  88.         ansiclose,
  89.     ansikopen,
  90.     ansikclose,
  91.         ttgetc,
  92.         ttputc,
  93.         ttflush,
  94.         ansimove,
  95.         ansieeol,
  96.         ansieeop,
  97.         ansibeep,
  98.     ansirev,
  99.     ansicres
  100. #if    COLOR
  101.     , ansifcol,
  102.     ansibcol
  103. #endif
  104. };
  105.  
  106. #if    COLOR
  107. ansifcol(color)        /* set the current output color */
  108.  
  109. int color;    /* color to set */
  110.  
  111. {
  112.     if (color == cfcolor)
  113.         return;
  114.     ttputc(ESC);
  115.     ttputc('[');
  116.     ansiparm(color+30);
  117.     ttputc('m');
  118.     cfcolor = color;
  119. }
  120.  
  121. ansibcol(color)        /* set the current background color */
  122.  
  123. int color;    /* color to set */
  124.  
  125. {
  126.     if (color == cbcolor)
  127.         return;
  128.     ttputc(ESC);
  129.     ttputc('[');
  130.     ansiparm(color+40);
  131.     ttputc('m');
  132.         cbcolor = color;
  133. }
  134. #endif
  135.  
  136. ansimove(row, col)
  137. {
  138.         ttputc(ESC);
  139.         ttputc('[');
  140.         ansiparm(row+1);
  141.         ttputc(';');
  142.         ansiparm(col+1);
  143.         ttputc('H');
  144. }
  145.  
  146. ansieeol()
  147. {
  148.         ttputc(ESC);
  149.         ttputc('[');
  150.         ttputc('K');
  151. }
  152.  
  153. ansieeop()
  154. {
  155. #if    COLOR
  156.     ansifcol(gfcolor);
  157.     ansibcol(gbcolor);
  158. #endif
  159.         ttputc(ESC);
  160.         ttputc('[');
  161.         ttputc('J');
  162. }
  163.  
  164. ansirev(state)        /* change reverse video state */
  165.  
  166. int state;    /* TRUE = reverse, FALSE = normal */
  167.  
  168. {
  169. #if    COLOR
  170.     int ftmp, btmp;        /* temporaries for colors */
  171. #endif
  172.  
  173.     ttputc(ESC);
  174.     ttputc('[');
  175.     ttputc(state ? '7': '0');
  176.     ttputc('m');
  177. #if    COLOR
  178.     if (state == FALSE) {
  179.         ftmp = cfcolor;
  180.         btmp = cbcolor;
  181.         cfcolor = -1;
  182.         cbcolor = -1;
  183.         ansifcol(ftmp);
  184.         ansibcol(btmp);
  185.     }
  186. #endif
  187. }
  188.  
  189. ansicres()    /* change screen resolution */
  190.  
  191. {
  192.     return(TRUE);
  193. }
  194.  
  195. ansibeep()
  196. {
  197.         ttputc(BEL);
  198.         ttflush();
  199. }
  200.  
  201. ansiparm(n)
  202. register int    n;
  203. {
  204.         register int q,r;
  205.  
  206.         q = n/10;
  207.         if (q != 0) {
  208.         r = q/10;
  209.         if (r != 0) {
  210.             ttputc((r%10)+'0');
  211.         }
  212.         ttputc((q%10) + '0');
  213.         }
  214.         ttputc((n%10) + '0');
  215. }
  216.  
  217. ansiopen()
  218. {
  219. #if     V7 | USG | BSD
  220.         register char *cp;
  221.         char *getenv();
  222.  
  223.         if ((cp = getenv("TERM")) == NULL) {
  224.                 puts("Shell variable TERM not defined!");
  225.                 exit(1);
  226.         }
  227.         if (strcmp(cp, "vt100") != 0) {
  228.                 puts("Terminal type not 'vt100'!");
  229.                 exit(1);
  230.         }
  231. #endif
  232.     strcpy(sres, "NORMAL");
  233.     revexist = TRUE;
  234.         ttopen();
  235. }
  236.  
  237. ansiclose()
  238.  
  239. {
  240. #if    COLOR
  241.     ansifcol(7);
  242.     ansibcol(0);
  243. #endif
  244.     ttclose();
  245. }
  246.  
  247. ansikopen()    /* open the keyboard (a noop here) */
  248.  
  249. {
  250. }
  251.  
  252. ansikclose()    /* close the keyboard (a noop here) */
  253.  
  254. {
  255. }
  256.  
  257. #if    FLABEL
  258. fnclabel(f, n)        /* label a function key */
  259.  
  260. int f,n;    /* default flag, numeric argument [unused] */
  261.  
  262. {
  263.     /* on machines with no function keys...don't bother */
  264.     return(TRUE);
  265. }
  266. #endif
  267. #else
  268. ansihello()
  269. {
  270. }
  271. #endif
  272. @
  273.